const dao= require('../../dao/daoenter.js');
const result= require('../../util/result/result.js');
const model  = require('../../dao/model/model');


/* 添加科目 */
    async function addkemu(req,res){
    /*   
    前端参数
            科目名  kemuName   字符串
            科目描述 kemuDesc  字符串
        */


            console.log(req.body,9999999);
            
            let obj={}
            obj.kemuName=req.body.kemuName
            obj.kemuDesc=req.body.kemuDesc
      
            let xx
          try {
            /* 保存到科目里，并获得科目的ID */
             xx=await  dao.daokemu.addkemu(obj)
          } catch (error) {
            console.log(error);
            res.send(result.result(false))
            
          }

          if(xx!=null){
            res.send(result.result(true,xx))
        }else{
            console.log(xx);
            res.send(result.result(false))
        }
        }


/* 查询科目 
skip
limit
*/
        async function queryAllkemu(req,res){
            // console.log(req.body,777777777);
            let skip=Number(req.body.skip)
            let limit =Number(req.body.limit)

            let xx
            try {
                xx=await  dao.daokemu.querykemuPages(skip,limit)  
            } catch (error) {
                console.log(error);
                res.send(result.result(false))
            }
            res.send(result.result(true,xx))
        }
        

 /* 修改科目 
 kemuID
 kemuName
 kemuDesc
 */ 
 async function  updatekemu(req,res){
    let obj={}
    obj.kemuName=req.body.kemuName
    obj.kemuDesc=req.body.kemuDesc


    let xx
    try {
        xx=await  dao.daokemu.updateKemu(req.body.kemuid,obj)  
    } catch (error) {
        console.log(error);
        res.send(result.result(false))
    }
    res.send(result.result(true,xx))
}

/* 删除科目 */
async function  deletekemu(req,res){
    let kemuID=req.body.kemuID
    let xx
    try {
        xx=await  dao.daokemu.deleteKemu(kemuID)  
    } catch (error) {
        console.log(error);
        res.send(result.result(false))
    }

    if(xx!=null){res.send(result.result(true))}else{res.send(result.result(false))}
    
}
 

   /* 查询指定职业包含的科目 */ 
   async  function queryProfessionIncludeKemu(req,res){
    /* 
    前端参数
    professionid   id 
    */

    let obj=new dao.daokemu.kemudao(model.modelkemuZhiye)
    let dd=await obj.getinfo(req.body.professionid)
    if(dd){
        res.send(result.result(true,dd))
       
    }else{
        res.send(result.result(false))
    }
   }



   /* 查询指定科目包含的知识点 */
   async function queryKemuIncludePoint(req,res){
    /* 前端参数
    kemuid  科目id  id
    
    */
    let obj=new dao.daopoint.point(model.modelpoint)
    let dd=await obj.findKemuIncludePoint(req.body.kemuid)
    if(dd){
        res.send(result.result(true,dd))
    }else{
        res.send(result.result(false))
    }
   }






module.exports={
	addkemu,queryProfessionIncludeKemu,queryKemuIncludePoint,queryAllkemu, updatekemu,deletekemu
}
